<template>
	<view>
		<!-- 固定图标的添加按键 -->
		<view  @click="xianshi()" v-if="addBi" style="position:fixed;top: 500rpx;z-index: 100; right: 30rpx;border-radius: 50%;background-color:blue;display: flex;justify-content: center;align-items: center;width: 100rpx;height: 100rpx;">
			<image style="width: 80rpx;height: 80rpx;" src="../../static/10.png" mode=""></image>
		</view>
		
		<!-- 最上面的【校区】选择 -->
		<u-tabs  style="height: 80rpx;" :current="current" :list="xiaoqulists" 
			scroll-y="true" lineWidth="50" lineColor="blue"
			:activeStyle="{ color: 'black',  transform: 'scale(1.1)'}"
			:inactiveStyle="{color: '#606266',transform: 'scale(0.9)'}"
			itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;" @change="change">
		</u-tabs>
			
		<!-- 根据选择的校区展示排课计划list -->
		<view style="display: flex;flex-direction: column;">
			<view v-for="(item,index) in paikelists" :key=index  style="display: flex;width: 85%;margin: 15rpx auto 0 auto;box-shadow: 1px 1px 5px #c2c2c2;padding: 20rpx 30rpx;border-radius: 15rpx;"  @click="topaike(item)">
				<view style="display: flex;flex:1;">
					{{index +1}}
				</view>
				<view style="display: flex;flex:10;">
					{{item.name}}
				</view>
			</view>
		</view>
			
		<!-- 下面是添加/修改【排课计划】出现的弹窗 -->
		<model v-if='paikejihuashow' @colseModel='paikejihuashow = false'>
			<view style="display: flex;background-color: blue;color: white;border-radius: 20rpx;padding: 15rpx ; margin: 25rpx auto;justify-content: center;">
				给【{{xuanzhongXiaoquName[0]}}】添加排课计划！
			</view>
			<view style="display: flex;margin-top: 30rpx;">校区</view>
				<uni-easyinput disabled type="text" v-model="xuanzhongXiaoquName[0]" placeholder="" />
			<view style="display: flex;margin-top: 30rpx;">输入新的排课计划名称</view>
			<uni-easyinput type="text" v-model="paikejihuaname" />
			<view style="display: flex;margin-top: 30rpx;">管理老师名字</view>
					<uni-easyinput disabled type="text" v-model="meiyi_name_tel.name" placeholder="请选择管理老师" />
			<view style="display: flex;margin-top: 30rpx;">管理老师电话</view>
			<uni-easyinput disabled type="text" v-model="meiyi_name_tel.mobile" />
			<view style="display: flex;width: 60%;justify-content: space-around;margin: 30rpx auto;color: white;">
				<view style="display: flex;background-color: blue;border-radius: 15rpx;padding: 20rpx 60rpx;" @click="addOrEditPaikejihua()">{{addOrXiugai}}</view>
				<view style="display: flex;background-color: blue;border-radius: 15rpx;padding: 20rpx 60rpx;" @click="paikejihuashow = false,addBi=1">取消</view>				
			</view>
		</model>
		
		
	</view>
</template>

<script>
	import getDateTime from '@/common/getdateTime.js';
	import model from '../../components/model.vue'
	export default {
		components: {
			model
		},
		data() {
			return {
				addOrXiugai:'',
				xiaoquname:'',
				addBi:1,
				paikejihuashow:0,
				paikejihuaedit:0,
				paikejihuaname:'',
				guanlilaoshiname:'',
				guanlilaoshitel:'',
				xiaoqulists:[],//去重后的校区
				meiyi_userinfo:[],//判断登陆人信息
				current:0,//UTAB的标签数字
				xuanzhongXiaoquName:[],
				paikelists:[]
			}
		},
		async onLoad() {
			this.meiyi_name_tel =await uni.getStorageSync('meiyi_name_tel')
			console.log(this.meiyi_name_tel);
			this.jingshouren = this.meiyi_name_tel.name + this.meiyi_name_tel.mobile
			this.xiaoqufun()
			// this.paikelistsfun()
		},
		methods: {
			topaike(e){
				uni.setStorageSync('aoyashengpaikelaiyuan',e)
				uni.navigateTo({
					url: '/pages/jiaoshi4/jiaoshi4'
				})
			},
			xianshi(){
				if(this.xuanzhongXiaoquName.length!=1){
					uni.showToast({
						title: '请选择校区后再次尝试！',
						icon: 'none',
						duration: 1000
					})
					return
				}else{
					this.addOrXiugai='添加'
					this.paikejihuashow=1
					this.addBi=0					
				}
			},
			// 获取我管理的校区
			async xiaoqufun(){
				const res=await uni.getStorageSync('aoyashengxiaoqu')
				this.xiaoqulists=[]
				let arr=[]
				for(var i=0;i<res.result.data.length;i++){
					var cou=0
					for(var j=i+1;j<res.result.data.length;j++){
						if(res.result.data[i].name==res.result.data[j].name){
							cou=9
							break
						}
					}
					if(cou==0){
						this.xiaoqulists.push(res.result.data[i])
						arr.push(res.result.data[i].name)
					}
				}
				this.allXiaoquName=arr
				if(this.xiaoqulists.length>1){
					this.xiaoqulists.unshift ({
						name:'全部'
					})
				}
				this.xuanzhongXiaoquName=this.allXiaoquName
				this.paikelistsfun()
			},
			//教室管理中进行切换
			change(e){
				this.paikelists=[]
				this.xuanzhongXiaoquName=[]
				if(e.name=='全部'){
					this.xuanzhongXiaoquName=this.allXiaoquName
					this.paikelistsfun()
				}else{
					this.xuanzhongXiaoquName.push(e.name)
					this.paikelistsfun()
				}
			},
			// 添加或者修改排课计划
			addOrEditPaikejihua(){
				if(this.paikejihuaname==''){
					uni.showToast({
						title: '请填写排课计划名称',
						icon: 'none',
						duration: 3000
					})
					return
				}
				uni.showLoading({
					title: '数据提交中…',
					mask: true
				});
				uniCloud.callFunction({
					name:"weifun",
					data:{
						leixing:7,//类型为1时，获取我管理的校区
						jingshouren:this.jingshouren,
						name:this.paikejihuaname,
						creat_time:getDateTime.dateTimeStr('y-m-d h:i:s'),
						xiaoqu:this.xuanzhongXiaoquName[0]
					}
				}).then(res=>{
					this.paikejihuaname=''
					this.paikejihuashow=0
					this.addBi=1
					uni.hideLoading()
					this.paikelistsfun()
				})
			},
			paikelistsfun(){
				console.log('1',this.xuanzhongXiaoquName)
				uni.showLoading({
					title: '数据获取中…',
					mask: true
				});
				uniCloud.callFunction({
					name:"weifun",
					data:{
						leixing:8,//类型为1时，获取我管理的校区
						xiaoqu:this.xuanzhongXiaoquName
					}
				}).then(res=>{
					this.paikelists=res.result.data
					console.log(this.paikelists)
					uni.hideLoading()
				})
			},
		}
	}
</script>

<style>

</style>
